package com.neiquan.backstage.resourec_manage.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neiquan.backstage.common.util.ExtraSpringHibernateTemplate;
import com.neiquan.backstage.pub.bsc.dao.po.Partner;
import com.neiquan.backstage.resourec_manage.PartnerService;

@Service
public class PartnerServiceImp implements PartnerService {
	private static Class<?> poc = Partner.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;

	@Override
	public void add(Partner entity) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().save(entity);
	}

	@Override
	public Partner queryById(int id) {
		// TODO Auto-generated method stub
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "partnerId", id);
	}

	@Override
	public void updata(Partner entity) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().update(entity);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Partner> queryAll() {
		// TODO Auto-generated method stub
		return (List<Partner>) extraSpringHibernateTemplate.findAll(poc);
	}

	@Override
	public Partner queryByName(String name, Integer memberId) {
		List<Partner> entrepreneurs = (List<Partner>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Partner where name=? and memberId=?", name,memberId);
		if(entrepreneurs.size()>0){
			return entrepreneurs.get(0);
		}
		return null;
	}

	@Override
	public List<Partner> queryByMemberId(Integer memberId) {
		// TODO Auto-generated method stub
		List<Partner> partners=	(List<Partner>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Partner where memberId=?", memberId);
		return partners;
	}
}
